Add gtk_native_dialog_destroy()
authorAlexander Larsson <alexl@redhat.com>
Wed, 11 Nov 2015 15:06:44 +0000 (16:06 +0100)
committerAlexander Larsson <alexl@redhat.com>
Wed, 11 Nov 2015 15:06:44 +0000 (16:06 +0100)
Its very easy to get extra references to the NativeDialog so that
when you release your last reference any visible dialog is not
hidden. We handle this by adding a destroy method similar to how
you destroy regular toplevels.

demos/gtk-demo/application.c
docs/reference/gtk/gtk3-sections.txt
gtk/gtkfilechooserbutton.c
gtk/gtknativedialog.c
gtk/gtknativedialog.h
tests/testgtk.c

index 02c12f95a5030f34134db16059b3e72c5a68d2b5..6124c3fce1cb39f471dbc296cdb99816ddb28bc3 100644 (file)
@@ -113,6 +113,7 @@ open_response_cb (GtkNativeDialog *dialog,
         }
     }
 
+  gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
   g_object_unref (native);
 }
 
index e8ad7578a42aa2d2bbae50735b16997fe199962e..767ad261d5dc2a184668207c6d334a30adc868f0 100644 (file)
@@ -2520,6 +2520,7 @@ GTK_TYPE_NATIVE_DIALOG
 GtkNativeDialogClass
 gtk_native_dialog_show
 gtk_native_dialog_hide
+gtk_native_dialog_destroy
 gtk_native_dialog_get_visible
 gtk_native_dialog_set_modal
 gtk_native_dialog_get_modal
index 1df73bc4b2c73b1cde27ed1708fea2f408385090..000482ebf8974e40e76ff212d70866f1cd25c315 100644 (file)
@@ -1008,7 +1008,11 @@ gtk_file_chooser_button_destroy (GtkWidget *widget)
       priv->dialog = NULL;
     }
 
-  g_clear_object (&priv->native);
+  if (priv->native)
+    {
+      gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (priv->native));
+      g_clear_object (&priv->native);
+    }
 
   priv->chooser = NULL;
 
index d67047c591ffa6668abcae40f8de94c306d8935b..e4fbb675bc01ed53b7f90829977811381cbb2e83 100644 (file)
@@ -361,6 +361,30 @@ gtk_native_dialog_hide (GtkNativeDialog *self)
   g_object_notify_by_pspec (G_OBJECT (self), native_props[PROP_VISIBLE]);
 }
 
+/**
+ * gtk_native_dialog_destroy:
+ * @self: a #GtkNativeDialog
+ *
+ * Destroys a dialog.
+ *
+ * When a dialog is destroyed, it will break any references it holds
+ * to other objects. If it is visible it will be hidden and any underlying
+ * window system resources will be destroyed.
+ *
+ * Note that this does not release any reference to the object (as opposed to
+ * destroying a GtkWindow) because there is no reference from the windowing
+ * system to the #GtkNativeDialog.
+ *
+ * Since: 3.20
+ **/
+void
+gtk_native_dialog_destroy (GtkNativeDialog *self)
+{
+  g_return_if_fail (GTK_IS_NATIVE_DIALOG (self));
+
+  g_object_run_dispose (G_OBJECT (self));
+}
+
 void
 _gtk_native_dialog_emit_response (GtkNativeDialog *self,
                                   int response_id)
index 8d5bd602344c9187b9e927f6ddcbb26b208ebb42..de1a6559a55a8af914183630e7c0703ef2ad791e 100644 (file)
@@ -54,6 +54,8 @@ void                  gtk_native_dialog_show (GtkNativeDialog *self);
 GDK_AVAILABLE_IN_3_20
 void                  gtk_native_dialog_hide (GtkNativeDialog *self);
 GDK_AVAILABLE_IN_3_20
+void                  gtk_native_dialog_destroy (GtkNativeDialog *self);
+GDK_AVAILABLE_IN_3_20
 gboolean              gtk_native_dialog_get_visible (GtkNativeDialog *self);
 GDK_AVAILABLE_IN_3_20
 void                  gtk_native_dialog_set_modal (GtkNativeDialog *self,
index 7dec326bcc4e3330c1ff29c8aa681777e18ad8f6..d00e7f7cadcd188bba87da2455209628d8a1e476 100644 (file)
@@ -9660,6 +9660,13 @@ native_filter_changed (GtkWidget *combo,
     }
 }
 
+static void
+destroy_native (GtkFileChooserNative *native)
+{
+  gtk_native_dialog_destroy (GTK_NATIVE_DIALOG (native));
+  g_object_unref (native);
+}
+
 void
 create_native_dialogs (GtkWidget *widget)
 {
@@ -9681,7 +9688,7 @@ create_native_dialogs (GtkWidget *widget)
                                             "_accept&native",
                                             "_cancel__native");
 
-      g_signal_connect_swapped (G_OBJECT (window), "destroy", G_CALLBACK (g_object_unref), native);
+      g_signal_connect_swapped (G_OBJECT (window), "destroy", G_CALLBACK (destroy_native), native);
 
       gtk_file_chooser_add_shortcut_folder (GTK_FILE_CHOOSER (native),
                                             g_get_current_dir (),